package commands;


import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.transfer.MultipleFileUpload;
import com.amazonaws.services.s3.transfer.Transfer;
import com.amazonaws.services.s3.transfer.TransferManager;
import jesss.commands.CommandResult;
import jesss.commands.JesssCommand;
import jesss.commands.JesssCommandFactoryImpl;
import jesss.commands.ResultStatus;
import jesss.options.JesssOptions;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.File;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;

/**
 * User: Lee
 * Date: 9/11/13
 * Time: 10:04 PM
 */
public class UploadDirectoryCommandTests extends CommandTestsBase {

    private AmazonS3 mockS3 = mock(AmazonS3.class);
    private TransferManager mockTransferManager = mock(TransferManager.class);
    private JesssOptions mockJesssOptions = mock(JesssOptions.class);
    private MultipleFileUpload mockMultipleFileUpload = mock(MultipleFileUpload.class);

    @Before
    public void Setup() {

        stub(mockMultipleFileUpload.getState()).toReturn(Transfer.TransferState.Completed);
        stub(mockTransferManager.uploadDirectory(anyString(), anyString(), any(File.class), anyBoolean())).toReturn(mockMultipleFileUpload);
        stub(mockJesssOptions.getAmazonS3()).toReturn(mockS3);
        stub(mockJesssOptions.getCommandName()).toReturn("ud");

    }

    @Test
    public void CanUploadDirectory() throws Exception {

        String[] args = {"-bn", "testBucket", "-k", "key", "-sd", "C:\\Temp", "-is"};
        JesssCommand uploadDirectoryCommand = JesssCommandFactoryImpl.getInstance().createCommand(mockS3, mockJesssOptions.getCommandName(), mockJesssOptions.getShouldDisplayVerbose(), args);

        CommandResult commandResult = uploadDirectoryCommand.executeCommand();
        Assert.assertEquals(commandResult.getResultStatus(), ResultStatus.Success);

    }

    @Test
    public void CannotUploadMissingDirectory() throws Exception {

        String[] args = {"-bn", "testBucket", "-k", "key", "-sd", "C:\\FakeDir", "-is"};
        JesssCommand uploadDirectoryCommand = JesssCommandFactoryImpl.getInstance().createCommand(mockS3, mockJesssOptions.getCommandName(), mockJesssOptions.getShouldDisplayVerbose(), args);

        CommandResult commandResult = uploadDirectoryCommand.executeCommand();
        Assert.assertEquals(commandResult.getResultStatus(), ResultStatus.Error);

    }
}
